package main

import (
	"flag"
	"log"
	"os"

	"github.com/libp2p/go-libp2p/core/crypto"
)

var (
	// Global variables
	genKey  = flag.Bool("k", false, "generate a new keypair")
	keyPath = flag.String("p", "priv.key", "path to the keypair")
)

func init() {
	// Parse flags
	flag.Parse()
}
func main() {
	if *genKey {
		priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 0)
		if err != nil {
			log.Panic(err)
		}
		keyData, err := crypto.MarshalPrivateKey(priv)
		if err != nil {
			log.Panic(err)
		}
		err = os.WriteFile(*keyPath, keyData, 0644)
		if err != nil {
			log.Panic(err)
		}
	}
}
